package com.liy.cloud.common.base.service.impl;

import java.util.List;
import java.util.Map;

import com.liy.cloud.common.base.dao.BaseEquGroupDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liy.cloud.common.base.dao.BaseEquInfoDao;
import com.liy.cloud.common.base.entity.BaseEquGroupEntity;
import com.liy.cloud.common.base.entity.BaseEquInfoEntity;
import com.liy.cloud.common.base.service.BaseEquInfoService;
import com.liy.cloud.common.vo.EquInfoVO;
import com.liy.cloud.common.vo.EquLayoutVO;
import com.das.framework.common.dao.IBaseDao;
import com.das.framework.common.service.impl.BaseServiceImpl;
import com.das.framework.common.utils.Tools;
import com.das.framework.common.vo.PageVO;


@Service
public class BaseEquInfoServiceImpl extends BaseServiceImpl<BaseEquInfoEntity, String> implements BaseEquInfoService {

    @Autowired
    private BaseEquInfoDao baseEquInfoDao;
    
    @Autowired
    private BaseEquGroupDao baseEquGroupDao;

    @Override
    public IBaseDao<BaseEquInfoEntity, String> getDao() {
        return baseEquInfoDao;
    }


    @Override
    public List<BaseEquInfoEntity> queryByTypeCodeOrDiviceType(BaseEquInfoEntity entity, PageVO<BaseEquInfoEntity> page) throws Exception {
        return baseEquInfoDao.queryByTypeCodeOrDiviceType(entity, page);
    }

    @Override
    public int addBaseEquInfo(BaseEquInfoEntity baseEquInfoEntity) throws Exception {
        return this.add(baseEquInfoEntity);
    }

    @Override
    public void deleteBatch(List<String> ids) {
        for (String id : ids) {
            baseEquInfoDao.deleteByPrimaryKey(id);
        }
    }


	@Override
	public List<BaseEquInfoEntity> findByMonitor(BaseEquInfoEntity entity, PageVO<BaseEquInfoEntity> page)
			throws Exception {

		return baseEquInfoDao.selectByMonitor(entity, page);
	}


	@Override
	public int updateAngleBatch(EquLayoutVO layoutVO) {
		
		if(layoutVO.getGroupList().size() > 0) {
			
			baseEquGroupDao.deleteByPrimaryStationId(layoutVO.getGroupList().get(0).getStation());
			for (BaseEquGroupEntity group : layoutVO.getGroupList()) {
				group.setId(Tools.getNewUUID());
				baseEquGroupDao.insertSelective(group);
//				if(Tools.StringIsNullOrSpace(group.getId())) {
//				}else {
//					baseEquGroupDao.updateByPrimaryKeySelective(group);
//				}
			}
		}
		return baseEquInfoDao.updateAngleBatch(layoutVO.getEquList());
	}
	
	public List<EquInfoVO> findAllAndType(EquInfoVO vo){
		return baseEquInfoDao.selectAllAndType(vo);
	}

    public List<BaseEquInfoEntity> getByParams(Map<String, Object> params, PageVO<BaseEquInfoEntity> page) throws Exception{
        return baseEquInfoDao.getByParams(params, page);
    }


    /**
     * 功能描述: 根据参数params查询设备信息
     *
     * @param: params： BaseEquInfoEntity  必须设置属性 ( 车站编号 stationid， 设备类型集合 devicetypesList)
     * @return:
     * @auther: liyang
     * @date: 2018/9/05 9:29
     */
    @Override
    public List<BaseEquInfoEntity> selectBySystemIdAndDeviceTypeList(BaseEquInfoEntity entity) {
        return baseEquInfoDao.selectBySystemIdAndDeviceTypeList(entity);
    }

    /**
     * 按照 stationid 和 devicetype 第一个字符来查询
     * @param: params： BaseEquInfoEntity  ( 车站编号 stationid， 设备类型 devicetype)
     * @return:
     * @auther: liyang
     * @date: 2018/9/05 9:29
     */
    @Override
    public List<BaseEquInfoEntity> selectByDeviceTypeSubFirst(BaseEquInfoEntity entity) {
        return baseEquInfoDao.selectByDeviceTypeSubFirst(entity);
    }

    /**
     * 按照 stationid 和 devicetype 前2个字符来查询
     * @param: params： BaseEquInfoEntity  ( 车站编号 stationid， 设备类型 devicetype)
     * @return:
     * @auther: liyang
     * @date: 2018/9/05 9:29
     */
    @Override
    public List<BaseEquInfoEntity> selectByDeviceTypeSubSecond(BaseEquInfoEntity entity) {
        return baseEquInfoDao.selectByDeviceTypeSubSecond(entity);
    }

    @Override
    public List<BaseEquInfoEntity> getInfoByPage(Map<String, Object> params, PageVO page) {
        return baseEquInfoDao.selectInfoByPage(params, page);
    }

    @Override
    public List<Map<String, Object>> getEquTypeTvmNum() throws Exception {
        return baseEquInfoDao.getEquTypeTvmNum();
    }

    @Override
    public List<Map<String, Object>> getEquTypeBomNum() throws Exception {
        return baseEquInfoDao.getEquTypeBomNum();
    }

    @Override
    public List<Map<String, Object>> getEquTypeAvmNum() throws Exception {
        return baseEquInfoDao.getEquTypeAvmNum();
    }

    @Override
    public List<Map<String, Object>> getEquTypeAgmNum() throws Exception {
        return baseEquInfoDao.getEquTypeAgmNum();
    }


}
